﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Web;
using System.Security.Principal;

namespace SalaDeEnsayo.ApplicationService
{
    public class BaseService
    {
        #region Vars

        Database salaDeEnsayoDB;
        
        #endregion

        #region Ctor

        public BaseService()
        {
            if (HttpContext.Current != null)
            {
                this.User = HttpContext.Current.User;
            }
        }

        #endregion

        #region Properties

        protected Database SalaDeEnsayoDB
        {
            get
            {
                if (this.salaDeEnsayoDB == null)
                {
                    this.salaDeEnsayoDB = this.CreateSalaDeEnsayoDB();
                }
                return salaDeEnsayoDB;
            }
        }

        protected IPrincipal User { get; set; }

        #endregion

        #region Private Methods

        private Database CreateSalaDeEnsayoDB()
        {
            return DatabaseFactory.CreateDatabase(GlobalConstants.UserDB);
        }

        #endregion
    }
}
